<?php

/**
 * 优惠券消息
 *
 * @author wxl
 * @time   2017-02-08
 */
class CouponMsgtpl extends BaseMsgtpl
{
	/**
	 * 
	 * @param array $userId		用户id
	 * @param array $accountId		帐号id
	 * @return
	 */
	public function sendMsg($userId,$accountId,$couponId)
	{
		$couponInfo = M('CouponInfo')->getByCouponId($couponId);
		$wechatUserInfo = D('Wechat/WechatUser')->getInfo(array('user_id' => $userId), 'openid,subscribe,wechat_id');
		$url = '';
		if($accountId == 28){//测试服
			$template_id = '_hHj0eU1ZQ7yorFomzpQvFV21NxQj8S_bqolOO9sbBk';//用待办事项测试
		}elseif($accountId == 3){//橄榄邦
			$template_id = 'SGQsFdvIKJV8wEqocDAHp-cokW7VZPX52M6hCBXfSlE';
		}

		if($wechatUserInfo && $wechatUserInfo['subscribe']){
            if($accountId == 28){
            	$info = array(
	                'first' => array("value" => '测试','color' => '#173177'),
	                'keyword1' => array("value" => '测试1' ),
	                'keyword2' => array("value" => date("Y-m-d H:i:s"),"color" => "#173177"),
	                'keyword3' => array("value" => date('Y-m-d H:i:s',strtotime("+1 hour")),"color" => "#173177" ),
	                'remark' => array("value" => "点击查看详情！","color" => "#173177"),
            	);
            
        	}elseif($accountId == 3){
        		$info = array(
	                'first' => array("value" => $couponInfo['title'],'color' => '#173177'),
	                'keyword1' => array("value" => $wechatUserInfo['nickname'] ),
	                'keyword2' => array("value" => $couponInfo['title'],"color" => "#173177"),
	                'keyword3' => array("value" => date('Y-m-d H:i:s'),"color" => "#173177" ),
	                'remark' => array("value" => "请在有效期内使用","color" => "#173177"),
            	);
        	}
            $result = $this->wxObj->messageTpl($this->wechatInfo['appid'], $this->wechatInfo['appsecret'], $wechatUserInfo['openid'], $template_id, $info, $url);
            return $result;
		}

		return false;
	}
	
	
}
